const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
  mode: "development",
  entry: "./src/main.js",
  output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js" },
  module: {
    rules: [
      { test: /\.vue$/, loader: "vue-loader" },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: { presets: ["@babel/preset-env"] },
        },
      },
      { test: /\.css$/, use: ["vue-style-loader", "css-loader"] },
    ],
  },
  resolve: {
    extensions: [".js", ".vue"],
    alias: { vue$: "vue/dist/vue.esm.js" },
  },
  devServer: {
    port: 3000,
    allowedHosts: ["all", ".alibaba-inc.com"],
    proxy: {
      "/api": {
        target: "http://localhost:9902",
        changeOrigin: true,
        pathRewrite: { "^/api": "" },
      },
    },
  },
  plugins: [
    new HtmlWebpackPlugin({ template: "./index.html", inject: "body" }),
    new VueLoaderPlugin(),
  ],
};
